package com.example.mydrawcircleprogress;

import com.example.mydrawcircleprogress.views.DobleCircleProgress;
import com.example.mydrawcircleprogress.views.CircleProgressView;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {
    private DobleCircleProgress   myp;
    private CircleProgressView mCompletedView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myp = (DobleCircleProgress) findViewById(R.id.MyCircleProgress);
        mCompletedView = (CircleProgressView) findViewById(R.id.tasks_view);
        new ProgressAnimation().execute();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    class ProgressAnimation extends AsyncTask<Void, Integer, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            for (int i = 0; i < 101; i++) {
                try {
                    publishProgress(i);
                    Thread.sleep(250);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            return null;
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            myp.setProgress(values[0]);
            mCompletedView.setProgress(values[0]);
            super.onProgressUpdate(values);
        }
    }

}
